package com.cskaoyan.mall.payment.controller.inner;

import com.alipay.api.AlipayApiException;
import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.pay.api.dto.PaymentInfoDTO;
import com.cskaoyan.mall.payment.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PayApiClient {
    @Autowired
    PayService payService;
    /**
     * 根据外部订单号 查询支付记录
     */
    @GetMapping("/api/payment/inner/getPaymentInfoByOutTradeNo/{outTradeNo}")
    PaymentInfoDTO getPaymentInfoDTOByOutTradeNo(@PathVariable(value = "outTradeNo") String outTradeNo){
        PaymentInfoDTO paymentInfoDTO = payService.getPaymentInfoDTOByOutTradeNo(outTradeNo);
        return paymentInfoDTO;
    }

    /**
     * 根据外部订单号 查询支付宝支付状态
     */
    @GetMapping("/api/payment/inner/getAlipayInfo/{outTradeNo}")
    Result getAlipayInfo(@PathVariable(value = "outTradeNo") String outTradeNo) throws AlipayApiException {
        String alipayInfo = payService.getAlipayInfo(outTradeNo);
        return Result.ok(alipayInfo);
    }

    /**
     * 关闭支付宝支付记录
     */
    @GetMapping("/api/payment/inner/closeAlipay/{outTradeNo}")
    Result closeAlipay(@PathVariable(value = "outTradeNo") String outTradeNo){
        return null;
    }

    /**
     * 修改paymentInfo为已关闭
     */
    @GetMapping("/api/payment/inner/closePaymentInfo/{outTradeNo}")
    Result closePaymentInfo(@PathVariable(value = "outTradeNo") String outTradeNo){
        payService.closePaymentInfo(outTradeNo);
        return  Result.ok();
    }
}
